<template>
  <Card title="工程项目信息" :loading="loading">
    <div ref="chartRef" :style="{ width, height }"></div>
  </Card>
</template>
<script lang="ts" setup>
  import { Ref, ref, watch } from 'vue';
  import { Card } from 'ant-design-vue';
  import { useECharts } from '/@/hooks/web/useECharts';

  const props = defineProps({
    loading: Boolean,
    width: {
      type: String as PropType<string>,
      default: '100%',
    },
    height: {
      type: String as PropType<string>,
      default: '400px',
    },
  });

  const chartRef = ref<HTMLDivElement | null>(null);
  const { setOptions } = useECharts(chartRef as Ref<HTMLDivElement>);
  watch(
    () => props.loading,
    () => {
      if (props.loading) {
        return;
      }
      setOptions({
        tooltip: {
          trigger: 'item',
        },
        legend: {
          bottom: '1%',
          left: 'center',
        },
        series: [
          {
            name: '项目阶段',
            type: 'pie',
            radius: '70%',
            center: ['50%', '50%'],
            color: ['#5473c4', '#91cc75', '#f8cd76', '#ec6464', '#7ac3c9 '],
            data: [
              { value: 65, name: '未分配' },
              { value: 16, name: '未进场' },
              { value: 31, name: '施工中' },
              { value: 33, name: '待验收' },
              { value: 74, name: '待结算' },
            ],
            // .sort(function (a, b) {
            //   return a.value - b.value;
            // })
            roseType: 'radius',
            animationType: 'scale',
            animationEasing: 'exponentialInOut',
            animationDelay: function () {
              return Math.random() *400;
            },
          },
        ],
      });
    },
    { immediate: true },
  );
</script>